<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>

  var reconstructQueue = function (people) {
    if (!people || !people.length) return [];
    people.sort((a, b) => a[0] === b[0] ? a[1] - b[1] : b[0] - a[0]);

    const res = [];
    people.forEach(item => {
      res.splice(item[1], 0, item); // 插入到k对应的位置
    })
    return res;
  };
  console.log(reconstructQueue(people = [[7, 0], [4, 4], [7, 1], [5, 0], [6, 1], [5, 2]]));
</script>

</html>